<?php
require_once("DatabaseConnect.php"); 
$con=Remoteconnect();
if($con==null){
	$con=Localconnect();	
}
session_start();
if (isset($_POST['email']))  //this could be more robust (check for our specific login form)
	{				
		// Get user's password from database and check if matches with input
		$user = $_POST['email'];
		$password=$_POST['password'];
		$sql=mysqli_query($con,"SELECT * FROM  `user` WHERE  `Email` = '$user'");
		$row = mysqli_fetch_array($sql);
		if($row==null){
			$sql="INSERT INTO `user` (`Email`, `Password`,`Session`) VALUES ('$user', '$password', '')";
					if (!mysqli_query($con,$sql))
						{
						  $_SESSION['msg'] = "Sorry, something whent wrong please try again";
							header("Location: ../Demo/register.php");
							exit();
						}else{
							mysqli_query($con, "INSERT INTO `userportfolio cash` (`Email`, `Cash`) VALUES('$user','0')");
						$_SESSION['Gmsg'] = "Successfully added to the database!";
							header("Location: /Demo");
							exit();
								
						}
			
		}else{
			$_SESSION['msg'] = "Email already in use!";
						header("Location: ../Demo/register.php");
						exit();
			
		}
		mysqli_close($con);
	}

?>